package lia.indexing;

import static lia.util.Constants.LUCENE_VERSION;

import java.io.IOException;

import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;

/**
 * index info
 * 
 * @author F.H Dragon(wenlong.meng@gmail.com)
 * @version 1.0 at 2011/08/07
 * @since 1.0
 */
public class VerboseIndexing {
	
	/**
	 * index datas
	 * 
	 * @throws IOException
	 */
	private void index() throws IOException {

		//build directory
		Directory dir = new RAMDirectory();
		//crate index writer
		IndexWriterConfig iwc = new IndexWriterConfig(LUCENE_VERSION,
				new WhitespaceAnalyzer(LUCENE_VERSION));
		iwc.setOpenMode(OpenMode.CREATE);
		IndexWriter writer = new IndexWriter(dir, iwc);

		//index info
		writer.setInfoStream(System.out);

		//Create documents
		for (int i = 0; i < 100; i++) {
			Document doc = new Document();
			doc.add(new Field("keyword", "goober", Field.Store.YES,
					Field.Index.NOT_ANALYZED));
			writer.addDocument(doc);
		}
		
		writer.optimize();
		writer.close();
	}

	/**
	 * test index info entry...
	 * 
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		VerboseIndexing vi = new VerboseIndexing();
		vi.index();
	}
}
